﻿using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows;
using System.Diagnostics;
using Module.Common.PubEvent;
using Module.Common.Common.QiPuHelper;
using Module.Common.Common;
using System.Windows.Threading;

namespace Module.Common.ViewModels
{
    /// <summary>
    /// 棋子类的ViewModel
    /// </summary>
    public class ChessPiecesViewModel : BindableBase
    {
        private readonly IEventAggregator Ea;
        public DelegateCommand QiZiClickCommand { get; private set; } // 点击棋子时的委托处理


        private bool _selected;
        public bool Selected { get { return _selected; } set { SetProperty(ref _selected, value); } }   // 棋子选中状态


        /// <summary>
        /// 以下选项可用于：ThreadOption
        /// PublisherThread： 使用此设置在发布商的线程上接收事件。这是默认设置。
        /// BackgroundThread： 使用此设置在.NET 框架线程池线程上异步接收事件。
        /// UIThread： 使用此设置在 UI 线程上接收事件。
        /// </summary>
        /// <param name="ea"></param>
        public ChessPiecesViewModel(IEventAggregator ea)
        {
            this.Ea = ea;
            Ea.GetEvent<ModuleMessageEvent>().Subscribe(ModuleMessageProcess);
            QiZiClickCommand = new DelegateCommand(()=> { Selected = true; });  // 棋子选中时，阴影扩大
        }

        /// <summary>
        /// 订阅消息处理
        /// </summary>
        /// <param name="obj">消息体</param>
        private void ModuleMessageProcess(ModuleMessage obj)
        {
            switch (obj.MessageName)
            {
                case "qiziGetClicked": Selected = false; break;  // 有棋子选中时，本棋子的Selected属性设置为false
                case "qiziMoveAnimationCompleted": Selected = false; break;   // 棋子移动结束
                default: break;
            }
        }
    }
}
